@isTest
private class CustomerRightsApplicationTest {
    static testMethod void testMethod1() {
        /*Country__c country = TestUtils.createCountry();
        country.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('OldCountryArchive','Country__c');
        insert country;*/
        /*
        Province__c province = TestUtils.createProvince();
        insert province;

        City__c city = TestUtils.createCity();
        city.Province__c = province.Id;
        insert city;

        District__c district = TestUtils.createDistrict();
        district.City__c = city.Id;
        insert district;*/

        Account acc = TestUtils.createAccount();
        acc.Name = '客户A';
        acc.Level__c = '一级医院';

        insert acc;

        AccountCredit__c ac = new AccountCredit__c();
        ac.Account__c = acc.Id;
        insert ac ;

        Event  e1 = new Event();
        e1.Account__c = acc.Id;
        e1.DurationInMinutes = 1;
        e1.ActivityDateTime = System.now();
        insert e1;

        Task t = new Task();
        t.WhatId = acc.Id;
        t.ActivityDate = System.today();
        t.OwnerId = UserInfo.getUserId();
        insert t;


        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        insert opp;

        Contract__c con = TestUtils.createContract();
        con.Account__c = acc.Id;
        con.ContractSource__c = '0';
        insert con ;

        InstallationApply__c ina = new InstallationApply__c();
        ina.Hospital__c = acc.Id;
        insert ina ;

        InstrumentDeliveryApplication__c inda  = new InstrumentDeliveryApplication__c();
        insert inda;


        Id ldcProfile = [Select Id From Profile Where Name ='销售部直销销售员'].Id;

        User u2 = new User( Alias = 'samLdc2', 
                Email = 'ldc@test.com.maike',
                Emailencodingkey = 'UTF-8', 
                Lastname = '用户2', 
                Languagelocalekey = 'en_US',
                Localesidkey = 'en_US', 
                Profileid = ldcProfile, 
                IsActive = true,
                CompanyName = 'Y-MKSY',
                FederationIdentifier = '123452',
                UserDepartment__c='客户服务中心(产品培训部)',
                Timezonesidkey = 'America/Los_Angeles', 
                EmployeeNumber = '123452',
                Province__c = '四川省',
                Username = 'Matldc2@test.com.maike' );
        u2.SubCompany__c = '四川省迈克实业有限公司';

        insert u2 ;


    System.runAs(u2){
         CustomerRightsApplicationController  ca = new CustomerRightsApplicationController();
        
        CustomerRightsApplicationController.findUser('用户2',null);
        ca.init();


        ca.searchJson = EncodingUtil.urlEncode('{"name":"客户A"}', 'UTF-8');
        ca.search();	

        ca.saveJson = EncodingUtil.urlEncode('[{"name":"客户A","accid":"'+acc.Id+'"}]', 'UTF-8');
        ca.otype = '新增共享权限';
        ca.atype = '客户团队权限共享';
        ca.userid = u2.Id ; 
        ca.pLine = '生化';
        ca.reason  = '1';
        ca.next();
        ca.saveData();

        CustomerRightsApplication__c can = [select Id,User__c  from CustomerRightsApplication__c limit 1 ];
        System.debug(can.User__c +' == '+ u2.Id);
        ca.caId = can.Id ; 
        ca.getDetails();

        can.Status__c = '审批成功';
        update can ;


        can.Status__c = '审批中';
        can.CustomerRightsType__c= '客户责任人转移';// '客户团队权限共享';
        update can ; 
        
         can.Status__c = '审批成功';
        update can ;
    }




    }
}